package cn.corffen.test.algorithm.leetcode.easy;

/**
 * 给你一个整型数，求它的逆序整型数
 */
public class ReverseInt7 {
    public static void main(String[] args) {

        int[] numbers = new int[]{123, 435, 2045678799,Integer.MAX_VALUE};
        for (int i = 0; i < numbers.length; i++) {
            System.out.println("reverse " + reverse(numbers[i]));
        }
    }

    public static int reverse(int x) {
        long res = 0;
        while (x != 0) {
            res = 10 * res + x % 10;
            x /= 10;
        }
        return res > Integer.MAX_VALUE || res < Integer.MIN_VALUE ? 0 : (int) res;
    }
}
